﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModelLayer;
using CtrLayer;

namespace GUILayer
{
    public partial class GUISaleDialogue : Form
    {
        CinemaController cinemaCtr = new CinemaController();
        RoomController roomCtr = new RoomController();
        public GUISaleDialogue()
        {
            InitializeComponent();
            PopulateCinemaDropdown();
        }

        private void buttonSaleDialogueOK_Click(object sender, EventArgs e)
        {
            if (!(comboBoxSaleDialogueCinema.SelectedIndex < 0 && comboBoxSaleDialogueRoom.SelectedIndex < 0))
            {
                try
                {
                    Cinema c = (Cinema)comboBoxSaleDialogueCinema.SelectedItem;
                    Room r = (Room)comboBoxSaleDialogueRoom.SelectedItem;
                    Form newForm = new GUISale(c, r);
                    this.Hide();
                    newForm.ShowDialog();
                    this.Close();
                }
                catch (InvalidCastException exp)
                {
                    MessageBox.Show("Vælg venligst en biograf og en sal");
                }
            }
            else
            {
                MessageBox.Show("Vælg venligst en biograf og en sal");
            }
            
        }

        private void comboBoxSaleDialogueCinema_SelectedIndexChanged(object sender, EventArgs e)
        {
            comboBoxSaleDialogueRoom.Items.Clear();
            Cinema c = (Cinema)comboBoxSaleDialogueCinema.SelectedItem;
            List<Room> roomList = roomCtr.GetRooms(c);
            comboBoxSaleDialogueRoom.Items.AddRange(roomList.ToArray());
            if (comboBoxSaleDialogueRoom.Items.Count > 0)
            {
                comboBoxSaleDialogueRoom.SelectedIndex = 0;
            }
            else
            {
                // no rooms
            }
        }

        public void PopulateCinemaDropdown()
        {
            comboBoxSaleDialogueCinema.Items.AddRange(cinemaCtr.GetCinemas().ToArray());
        }
    }
}
